package com.gzl.test.struts.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;


import com.opensymphony.xwork2.ActionSupport;

public class Upload2Action extends ActionSupport {
	private String title;
	
	private File upload;  //封装上传文件域
	private String uploadContentType; //封装上传文件类型
	private String uploadFileName; //封装上传文件名
	
	private String savePath;
	
    //get和set方法，省略！

	public String execute() throws Exception{
		System.out.println(uploadFileName);
		System.out.println(uploadContentType);
		FileOutputStream fos = new FileOutputStream(getSavePath()+getUploadFileName());
		FileInputStream fis = new FileInputStream(getUpload());
		byte[] buf = new byte[1024];
		int len = 0;
		while((len = fis.read(buf))>0){
			fos.write(buf, 0, len);
		}
		
		fos.close();
		fis.close();
		
		return SUCCESS;
		
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the upload
	 */
	public File getUpload() {
		return upload;
	}

	/**
	 * @param upload the upload to set
	 */
	public void setUpload(File upload) {
		this.upload = upload;
	}

	/**
	 * @return the uploadContentType
	 */
	public String getUploadContentType() {
		return uploadContentType;
	}

	/**
	 * @param uploadContentType the uploadContentType to set
	 */
	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	/**
	 * @return the uploadFileName
	 */
	public String getUploadFileName() {
		return uploadFileName;
	}

	/**
	 * @param uploadFileName the uploadFileName to set
	 */
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	/**
	 * @return the savePath
	 */
	public String getSavePath() {
		return savePath;
	}

	/**
	 * @param savePath the savePath to set
	 */
	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}
	
	
	

}
